<template>
  <div class="user">
    <div class="userBox">
      <div class="userTitle">{{userData.screenName}}的个人世界</div>
      <img :src="userData.head" alt="头像不见了捏"/>
      <div class="userContent">
        <div>
          <p>本名：{{userData.properName}}</p>
          <p>性别：{{userData.sex}}</p>
          <p>生日：{{userData.birthday}}</p>
        </div>
        <div>
          <p>职业：{{userData.occupation}}</p>
          <p>电话：{{userData.telephone}}</p>
          <p>邮箱：{{userData.mailbox}}</p>
        </div>
      </div>
      <div class="signature">
        <span>此时相望不相闻，愿逐月华流照君。</span>
        <span>——《春江花月夜》</span>
      </div>
    </div>
  </div>
</template>

<script setup>

import {reactive, onBeforeMount} from "vue";
import {http} from "../axios/index.js"

//基本信息
const userData = reactive({
  head: "",
  screenName: "",
  properName: "",
  birthday: "",
  sex: "",
  occupation: "",
  telephone: "",
  mailbox: ""
})

//获取基本信息
async function getUser(){
  const res = await http({
    url: "/get_user",
    method: "POST"
  })
  if(res.data.code === 0){
    for (const key in res.data.data) {
      userData[key] = res.data.data[key]
    }
  }
}

onBeforeMount(()=>{
  getUser()
})
</script>

<style scoped>
.user{
  background: url("/assets/user/user_bg.jpg") bottom right;
}
.user .userBox{
  width: 90vw;
  max-width: 600px;
  backdrop-filter: blur(5px);
  box-shadow: 5px 5px 10px #444444;
  border-radius: 10px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
}
.userBox .userTitle{
  width: 100%;
  text-align: center;
  font-size: 1.3rem;
  font-weight: bold;
  line-height: 2;
}
.userBox img{
  width: 150px;
  height: 150px;
  border-radius: 50%;
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%,-50%);
}
.userBox .userContent{
  display: flex;
  justify-content: space-around;
  padding: 20px 20px 10px;
}
.userBox .userContent p{
  line-height: 1.5;
  font-size: 1.2rem;
}
.userBox .signature {
  text-align: center;
  line-height: 1.5;
  padding: 0 10px 10px;
}
@media (max-width: 800px){
  .userBox .userTitle{
    margin-top: 30px;
  }
  .userBox img{
    left: 50%;
    transform: translate(-50%,-80%);
  }
  .userBox .userContent{
    flex-direction: column;
  }
}
@media (max-width: 450px) {
  .userBox .signature {
    display: grid;
    grid-template-columns: 1fr;
    text-align: left;
  }
  .userBox .signature span:last-child{
    text-align: right;
  }
}
</style>